Hey Paul,
Sorry for late answer. I had some busy time after the New Year's :)
Let me understand the intention of the patch correctly. You cannot
drop your own IMockitoConfiguration due to some OSGI constraints. So
you're looking for a way to change the default mockito configuration
in a different way. Say we accept the patch with a setter method in a
DefaultMockitoConfiguration. When do you call this method?
Cheers!
--
On Mon, Jan 28, 2013 at 12:11 PM, Paul Richardson
<enig...@googlemail.com> wrote:
> Hi,
>
> Working on an eclipse project called Teiid Designer and we use mockito in
> our unit tests. In order to only have one mockito jar library in the
> codebase, we wrap the mockito-all jar as an OSGI plugin (essentially a jar
> with extra OSGI metadata). This means the plugin is loaded at the beginning
> of the set of unit tests then depended on by each executing test plugin.
>
> However, I have found a problem with the way objenesis caches mocked
> classes. Since the cache is keyed on the package/classname, two different
> classes that happen to share this key will conflict and the wrong one be
> used. This use case occurs in our codebase since we carry separate plugins
> of different versions of the same runtime client. The result is that tests
> based on one version of the runtime client cache its mocked classes then
> subsequent tests based on the second runtime client fail since attempts to
> mock its classes return the wrong mocked classes from the cache, resulting
> in ClassCastExceptions.
>
> The workaround is to turn the objensis cache off but due to eclipse's bundle
> class loading system it is impossible to derive a Configuration class, in a
> test plugin, that will get loaded by the mockito plugin's class loader. I
> have worked around this by adding an addition Configuration class in the
> mockito plugin itself but I have provided a patch to the
> DefaultMockitoConfiguration that will achieve the same result.
>
> Any chance this could be added into mocktio?
>
> Happy to provide further information if this is in any way confusing...
>
> Thanks
>
> PGR
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "mockito" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mockito+u...@googlegroups.com.
> To post to this group, send email to moc...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mockito?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Szczepan Faber
Principal engineer@gradleware
Lead@mockito
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Just to add some more info on this problem.The problem we got is that we have a set of osgi bundles, which inside them contain different versions of a jar.Lets call them org.fwk.runtime_1-8.0.0 and org.fwk.runtime_2-8.0.0.These have different bundle names, but contain jar with same classes for the tools to be able to work with multiple runtimes at a time (same situation if you had a project that would need to reach and use different jdbc versions of a database vendor)Now we want to add tests for this using Mockito.Mockito unfortunately *Caches* classes via name, thus it will after you have tested org.fwkruntime_1 not load org.fwkruntime_2 in its tests and we are screwed.To fix that there are two options:1) add mockito.jar to each and every test bundle (that doesn't scale well)2) disable the mockito caching....one would think #2 would be easy but because Mockito only allow overriding of its DefaultMockitoConfiguration by creating an org.mockito.MockitoConfiguration class that is also not possible since:a) putting that class in each test bundle will not make it seen by Mockito (since mockito wont have it is on its classpath)b) having same package name in two different jars messes up signing jarsThus we need an explicit way of disable caching or/and a non-classloader dependent way of overriding Mockito's DefaultMockitoConfigruation.This is what we are forced to right now:and for each test that needs to disable caching we do this:And I really would prefer not to have this custom customization exposed via org.mockito.* name space in all our eclipse projects.Not good.If you guys have another way of overriding this configuraiton that avoids this that would be very much appreciated.